package com.example.mall.web.controller;

import com.example.mall.domain.SmsNotifications;
import com.example.mall.dto.SmsNotificationsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SmsNotificationsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISmsNotificationsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/smsNotifications")
public class SmsNotificationsController {

    @Autowired
    public ISmsNotificationsService smsNotificationsService;

    /**
     * 分页查询短信通知表信息
     * @param smsNotificationsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询短信通知表信息",notes = "分页查询短信通知表信息",httpMethod = "GET")
    public JSONResult queryPage(SmsNotificationsQuery smsNotificationsQuery){
        PageDTO<SmsNotificationsDto> smsNotificationsDtoPageDTO = smsNotificationsService.queryPage(smsNotificationsQuery);
        return JSONResult.success("查询成功",smsNotificationsDtoPageDTO);
    }

    /**
     * 根据id查询短信通知表信息
     * @param smsId
     * @return
     */
    @GetMapping("query/{smsId}")
    @ApiOperation(value = "根据id查询短信通知表信息",notes = "根据id查询短信通知表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("smsId")Long smsId){
        //1.根据id查询用户信息
        if (smsId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SMSID_NOT_ID);
        }
        SmsNotifications smsNotifications = smsNotificationsService.getById(smsId);
        return JSONResult.success("查询成功",smsNotifications);
    }

    /**
     * 根据id查询短信通知表信息
     * @param smsId
     * @return
     */
    @GetMapping("querySmsNotificationsById/{id}")
    @ApiOperation(value = "根据id查询短信通知表信息",notes = "根据id查询短信通知表信息",httpMethod = "GET")
    public JSONResult querySmsNotificationsById(@PathVariable("smsId")Long smsId){
        //1.根据id查询用户信息
        if (smsId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SMSID_NOT_ID);
        }
        SmsNotifications smsNotifications = smsNotificationsService.querySmsNotificationsById(smsId);
        return JSONResult.success("查询成功",smsNotifications);
    }

    /**
     * 查询全部短信通知表信息
     * @param
     * @return
     */
    @GetMapping("querySmsNotificationsList")
    @ApiOperation(value = "查询全部短信通知表信息",notes = "查询全部短信通知表信息",httpMethod = "GET")
    public JSONResult querySmsNotificationsList(){
        List<SmsNotifications> logins = smsNotificationsService.querySmsNotificationsList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增短信通知表
     * @param smsNotificationsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增短信通知表",notes = "新增短信通知表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SmsNotificationsDto smsNotificationsDto){
        smsNotificationsService.insert(smsNotificationsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改短信通知表信息
     * @param smsNotificationsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改短信通知表信息",notes = "修改短信通知表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SmsNotificationsDto smsNotificationsDto){
        smsNotificationsService.update(smsNotificationsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除短信通知表信息
     * @param smsId
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除短信通知表信息",notes = "删除短信通知表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("smsId") Long smsId) {
        smsNotificationsService.delete(smsId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除短信通知表信息
     * @param smsIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除短信通知表信息",notes = "批量删除短信通知表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> smsIds) {
        smsNotificationsService.deleteBatch(smsIds);
        return JSONResult.success("批量删除成功");
    }
}
